import { onDestroy } from "svelte";
import { writable } from "svelte/store";

export const useClickLocation = () => {
    const loc = writable({ x: 0, y: 0 });

    const onClick = (e) => {
        const { clientX, clientY } = e;
        loc.set({ x: clientX, y: clientY });
    }
    document.addEventListener('mousedown', onClick)

    onDestroy(() => {
        document.removeEventListener('mousedown', onClick);
    })
    return loc;
}